/**
 * 
 */
package top.lcpsky.flashcards.web;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**   
 * @ClassName:  LoginController   
 * @author: lcp
 * @date:   2020年5月9日 下午8:30:13   
 *     
 * @Copyright: 2020 www.ankept.com Inc. All rights reserved. 
 */
@RequestMapping("/sign")
@Controller
public class SignController {
	private static final String USERNAME = "admin";
	private static final String PASSWARD = "14789632";

	
	@RequestMapping("/in")
	public String signIn(HttpSession session,@RequestParam(name = "username")String username,@RequestParam(name = "password")String password) {
		Boolean hasSignIn = false; 
		hasSignIn = passwordMatcher(username,password);
		if(hasSignIn) {
			session.setAttribute("loginStatus", true);
			session.setAttribute("userName", username);
			return "redirect:/cards";
		}else {
			session.setAttribute("loginStatus", false);
			return "login";
		}
	}
	@RequestMapping("/out")
	public String signOut(HttpSession session) {
		session.invalidate();
		return "redirect:/login";
	}

	private Boolean passwordMatcher(String username, String password) {
		return USERNAME.equals(username)?PASSWARD.equals(password):false;
	}
}
